package com.fz.controller;

import com.fz.mapper.StudentMapper;
import com.fz.util.MybatisUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ZCY on 2018-01-26.
 */
@Controller
public class ok {
    /*向数据库进行查询*/
    @RequestMapping("/stu")
    public String sss(Model m){
        m.addAttribute("sts",new MybatisUtil().getSession().getMapper(StudentMapper.class).showName());
        return "student";
    }



    @RequestMapping("/ok")
    public String show(String name ,Model model) {
      model.addAttribute("name",name);
      model.addAttribute("age",19);
        return "ok";
    }

    @RequestMapping("/uu") @ResponseBody
            public String uu(){
        return"user中国人";
        }
      @RequestMapping("ii")
        public void ii(HttpServletResponse res) throws IOException {
          res.setCharacterEncoding("utf-8");
          res.setContentType("text/html;charset=utf-8");
          PrintWriter p = res.getWriter();
          p.print("user--是中国人");
          p.flush();
          p.close();
        }




        @RequestMapping("/aaa")
        public ModelAndView abc(String name){
         ModelAndView mv=new ModelAndView("ok");
        //  mv.addObject("name","李四四");
        mv.addObject("name", name);
        return mv;
}


}
